#encoding:utf-8
import os
import pandas as pd
import numpy as np
# 功能：数据翻转
def reversed_data(sentence):
    word_list = sentence.split(" ")
    word_list.reverse()
    return " ".join(word_list)

if __name__ == '__main__':

    # 配置
    config = {}
    config['status'] =  '_re'
    config['isDemo'] =  False
    if config['isDemo']:
        config['commonPath'] =  "../data/"
        config['origin_trainPath'] ="{0}train_set_demo.csv".format(config['commonPath']) 
        config['origin_testPath'] ="{0}test_set_demo.csv".format(config['commonPath']) 
        config['trainPath'] ="{0}train_set_demo_{1}.csv".format(config['commonPath'],config['status']) 
        config['testPath'] ="{0}test_set_demo_{1}.csv".format(config['commonPath'],config['status']) 
    else:
        config['commonPath'] =  "D:/project/python_wp/nlp/team-learning-nlp/NewsTextClassification/data/"
        config['origin_trainPath'] ="{0}train_set.csv".format(config['commonPath']) 
        config['origin_testPath'] ="{0}test_a.csv".format(config['commonPath']) 
        config['trainPath'] ="{0}train_set{1}.csv".format(config['commonPath'],config['status']) 
        config['testPath'] ="{0}test_a{1}.csv".format(config['commonPath'],config['status']) 
    print("config:{}".format(config))

    # 数据处理
    train_df = pd.read_csv(config['origin_trainPath'],sep='\t')
    train_df['reverse_text'] = train_df['text'].apply(reversed_data)
    train_df = train_df[['label','reverse_text']]
    train_df.columns = ['label','text']
    train_df.to_csv(config['trainPath'],sep="\t",index=None)
    del train_df

    test_df = pd.read_csv(config['origin_testPath'],sep='\t')
    test_df['reverse_text'] = test_df['text'].apply(reversed_data)
    test_df = test_df[['reverse_text']]
    test_df.columns = ['text']
    test_df.to_csv(config['testPath'],sep="\t",index=None)
    del test_df


    